/*
* Copyright (c) 2006 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_DXINPUTSYSTEM_H
#define M_DXINPUTSYSTEM_H

#include "dxheaders.h"

#include "inputsystem.h"
#include "comptr.h"
#include "common.h"


namespace Engine
{
	/**
	*   Input system based on DirectInput.
	*/
	class DXInputSystem: public InputSystem
	{
	public:

		DXInputSystem();

		~DXInputSystem();

		/**
		*   Initialize system.
		*   @param param system specific parameter.
		*/
		virtual void Init(RefPtr<RenderWindowInfo> param, bool exclusive);

		/**
		*   Close all devices.
		*/
		virtual void Close();

		/**
		*   Absolute position of the mouse.
		*/
		virtual void GetMousePosition( REAL* x_pos, REAL* y_pos ) const;

		/**
		*   Update device state.
		*/
		virtual void Update();

		/**
		*   Set mouse  moving area dimensions.
		*/
		virtual void SetMouseArea(unsigned int width, unsigned int height);

		/**
		*   Return true in system is in exclusive mode.
		*/
		virtual bool IsExclusive();

		/**
		*   Toggle exclusive mode.
		*/
		virtual void ToggleExclusive(bool val);

	private:

		void InitLocal();

		void InitKeyboard();

		void InitMouse();

	private:

		HWND m_hWnd;

		ComPtr<IDirectInput8>  m_diObject;

		ComPtr<IDirectInputDevice8> m_diKeyboard;

		ComPtr<IDirectInputDevice8> m_diMouse;

		REAL m_mouseX;

		REAL m_mouseDeltaX;

		REAL m_mouseY;

		REAL m_mouseDeltaY;

		REAL m_mouseWeel;

		REAL m_mouseWeelDelta;


		unsigned int m_screenWidth;
		unsigned int m_screenHeight;

		bool m_isExclusive;
	};

	/**
	*   Factory for creating input systems.
	*/
	class DXInputSystemFactory: public InputSystemFactory
	{
	public:

		DXInputSystemFactory():m_type("DirectXInputSystem"){}

		/**
		*   Returns the factory type.
		*/
		virtual const std::string& GetType() const {return m_type;}

		/**
		*   Creates a new object.
		*   @param name Name of the object to create
		*   @return	An object created by the factory. The type of the object depends on	the factory.
		*/
		virtual InputSystem* CreateInstance( const std::string& );

	private:

		std::string m_type;
	};
}

#endif
